import { getLocal } from "@/common/utils"

export const inspect =(router) =>{
    router.beforeEach((to,from,next)=>{
    if(!to.matched.some(record=>record.meta.auth)){
        if(getLocal("token") == null){
            alert("您没有登录，请先登录系统!");
            console.log(to.path);
            console.log(from.path);
            if (!from.path.startsWith('/login')) {
                next({
                  path: '/login',
                  query: { redirect: from.fullPath }  // 重定向到当前访问的路径
                });
            }
        } else {
            next()
        }
    } else {
        next()
    }})
}